<template>
  <el-dialog title="按收货单添加商品" :close-on-click-modal="false" :visible.sync="visible" center fullscreen append-to-body>
    <el-form :model="dataForm" ref="dataForm" label-width="80px">
      <el-row>
        <el-col :span="8">
          <el-form-item label="收货单号">
            <el-input v-model="dataForm.linkBillId"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="收货人">
            <el-input v-model="dataForm.createUserName"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="制造商">
            <el-input v-model="dataForm.supplyName">
              <el-button slot="append" @click="choiceSupply">选择</el-button>
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item label="收货日期">
        <el-row>
          <el-col :span="11">
            <el-date-picker v-model="dataForm.createTimeStart" style="width: 100%;" value-format="yyyy-MM-dd"></el-date-picker>
          </el-col>
          <el-col class="line" :span="2" style="text-align: center;">-</el-col>
          <el-col :span="11">
            <el-date-picker v-model="dataForm.createTimeEnd" style="width: 100%;" value-format="yyyy-MM-dd"></el-date-picker>
          </el-col>
        </el-row>
      </el-form-item>
      <el-form-item>
        <el-button icon="el-icon-search" type="primary" plain @click="getDataList">查询</el-button>
        <el-button icon="el-icon-search" type="info" plain @click="clearSearchForm">清除</el-button>
      </el-form-item>
    </el-form>
    <div class="avue-crud">
    <el-table :data="dataList" height="calc(100vh - 215px)" border v-loading="dataListLoading">
      <el-table-column type="index" width="50">
      <template slot-scope="scope">
        <el-radio v-model="dataForm.id" :label="scope.row.id" style="position: relative;left: 6px;top:-2px;" @change="checkInfo(scope.row)">&nbsp;</el-radio>
      </template>
    </el-table-column>
      <el-table-column prop="billId" label="收货单号"></el-table-column>
      <el-table-column prop="supplyName" label="制造商"></el-table-column>
      <el-table-column prop="createUserName" label="制单人"></el-table-column>
      <el-table-column prop="createTime" label="收货日期"></el-table-column>
    </el-table>
    </div>
    <div class="avue-crud__pagination">
      <el-pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" :current-page="pageIndex"
        :page-sizes="[10, 20, 50, 100]" :page-size="pageSize" :total="totalPage" background layout="total, sizes, prev, pager, next">
      </el-pagination>
    </div>
    <search-supply v-if="supplyVisible" ref="supplyDialog" @refreshData="getSupplyData"></search-supply>
  </el-dialog>
</template>

<script>
  import SearchSupply from '@/components/business/SearchSupply'
  import { receiveGoodsFetchList } from '@/api/eims/purchase/receive-goods'
  import { filterParams } from "@/util/tools";


    export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          applyStatus: '2',
          outDeptId: '',
          outDeptName: '',
          inDeptId: '',
          inDeptName: '',
          memo: '',
          supplyName: ''
        },
        dataList: [],
        pageIndex: 1,
        pageSize: 100,
        totalPage: 0,
        dataListLoading: false,
        receiveListVisible: false,
        supplyVisible: false,
      }
    },
    components: {
      SearchSupply
    },
    methods: {
      init(data) {
        this.clearSearchForm()
        this.visible = true
        this.dataList = []
        this.dataForm.lensFlag = data
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
        })
      },
      // 每页数
      sizeChangeHandle(val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle(val) {
        this.pageIndex = val
        this.getDataList()
      },
      //清空
      clearSearchForm(){
        for(var key in this.dataForm){
          this.dataForm[key] = ''
        }
      },
      handleSelectionChange(val) {
        this.selectList = val
      },
      getDataList(){
        this.dataListLoading = true
        let params1 = { current: this.pageIndex, size: this.pageSize };
        let params2 = filterParams(this.dataForm);
        receiveGoodsFetchList(Object.assign(params1, params2)).then(response => {
          if(response.data.code == '0'){
            this.dataList = response.data.data.records
            this.totalPage = response.data.data.total
          }else{
            this.$message.error(response.data.msg)
          }
          this.dataListLoading = false
        })
      },
      //选择制造商
      choiceSupply() {
        this.supplyVisible = true
        this.$nextTick(() => {
          this.$refs.supplyDialog.init({ctgId: ''})
        })
      },
      getSupplyData(data) {
        this.dataForm.supplyId = data.id
        this.dataForm.supplyName = data.name
      },
      // 选择收货单
      checkInfo(val) {
        this.visible = false
        this.$emit('reshFormData',val)
      },
    }
  }
</script>
